#pragma once
#include "IMediaBridgeSourceFilter.h"

class CMediaBridgeSourceFilterPin : public CSourceStream
{
private: 
	REFERENCE_TIME	m_rtSampleTime;
	int				m_videoWidth, m_videoHeight;
	DWORD			m_fourCC;
	GUID			m_mediaSubType;
	int				m_bitCount;
	
protected:
	HRESULT OnThreadCreate(void);
	HRESULT OnThreadDestroy(void);
	HRESULT OnThreadStartPlay(void);

	CCritSec m_cSharedState;
	
public:
	DECLARE_IUNKNOWN;
	virtual HRESULT Stop(void);
	CMediaBridgeSourceFilterPin(HRESULT *phr, CSource *pFilter);
	~CMediaBridgeSourceFilterPin();

	HRESULT GetMediaType(CMediaType *pMediaType);
	HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
	HRESULT FillBuffer(IMediaSample *pSample);

	void SetVideoDimensions(int VideoPixelWidth, int VideoPixelHeight, int BitCount, DWORD FourCC, GUID MediaSubType);
	STDMETHODIMP Notify(IBaseFilter *pSelf, Quality q);
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
};

class CMediaBridgeSourceFilter : public CSource,
								 public IFileSourceFilter,
								 public IMediaBridgeSourceFilter
{
public:
	DECLARE_IUNKNOWN;
	static CUnknown *		WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);
	STDMETHODIMP			NonDelegatingQueryInterface(REFIID riid, void ** ppv);
	STDMETHODIMP			Stop(void);
	STDMETHODIMP			GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt);
	STDMETHODIMP			Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt);
	STDMETHODIMP			InitializeVideo(int VideoPixelWidth, int VideoPixelHeight, int BitCount, DWORD FourCC, GUID MediaSubType);
	STDMETHODIMP			SendSample(char * pBuffer, int BufferLen);
	STDMETHODIMP			SetCallback(IMediaBridgeCallback *CallbackInstance);
	IMediaBridgeCallback *	GetCallBackInstance();
	~CMediaBridgeSourceFilter();

private:
	CMediaBridgeSourceFilter(LPUNKNOWN punk, HRESULT *phr);

	CCritSec					m_cSharedState;
	IMediaBridgeCallback		* m_callBackInstance;
	CMediaBridgeSourceFilterPin * m_pPin;
	CCritSec					m_MediaBridgeSourceFilterLock;
};

